package main

import (
  "flag"
  "fmt"
  "os"
)

func PrimeFactorSum(n int) int {
  notPrime := make([]bool, n + 1)
  rem := n
  sum := 0
  nextPrime := 2
  for {
    if rem % nextPrime == 0 {
      sum += nextPrime
      for {
        rem /= nextPrime
        if rem % nextPrime != 0 {
          break
        }
      }
    }
    if rem <= 1 {
      break
    }
    last := n / nextPrime
    for i := 2; i <= last; i++ {
      notPrime[i * nextPrime] = true
    }
    for nextPrime = nextPrime + 1; notPrime[nextPrime]; nextPrime++ { }
  }
  return sum
}

func main() {
  n := flag.Int("n", 1, "Sum up unique prime factors of n")
  flag.Parse()
  fmt.Fprintf(os.Stdout, "%d\n", PrimeFactorSum(*n))
}
